﻿using System.Diagnostics;
using TechTalk.SpecFlow;
using WatiN.Core;

namespace Sketch.Test.Acceptance
{
    [Binding]
    public class WebBrowser
    {
        static WebBrowser()
        {
            Settings.Instance.WaitUntilExistsTimeOut = 300;
            Settings.Instance.WaitForCompleteTimeOut = 300;
        }

        public static Browser Current
        {
            get
            {
                if (!ScenarioContext.Current.ContainsKey("browser"))
                {
                    try
                    {
                        foreach (var p in Process.GetProcessesByName("iexplore"))
                            p.Kill();
                    }
                    catch {}

                    ScenarioContext.Current["browser"] = new IE();
                }

                return (Browser)ScenarioContext.Current["browser"];
            }
        }


        [BeforeStep]
        public static void BeforeStep()
        {
            try
            {
                Current.WaitForAjaxRequest();
                Current.WaitForComplete();
            }
            catch { }            
        }
    }
}
